Graphing live Twitter sentiment

by: Rasil, 7 years ago


I am trying to draw a live graph, however the graph doesn't open up in a new window and it doesn't update. I used the code from this website. I am currently using Python 3.5.2

[Code:]

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import time

style.use("ggplot") #makes the graph look better

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

def animate(i):
    pullData = open("twitter-out1.txt","r").read()
    lines = pullData.split('n')

    xar = [] #x-array
    yar = [] #y-array

    x = 0
    y = 0

    for l in lines:
        x += 1
        if "pos" in l:
            y += 1
        elif "neg" in l:
            y -= 1

        xar.append(x)
        yar.append(y)
        
    ax1.clear()
    ax1.plot(xar,yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()

I have no problem in getting the tweets, but the graph doesn't move. Is there a way to fix this?




You must be logged in to post. Please login or register an account.